package org.monster.context.core.headerfilter;

import org.monster.context.core.parameter.HttpResponse;
import org.monster.context.core.request.HttpRequest;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础过滤器通道
 *
 * @author Monster
 */
public class BaseFilterChain {

    /**
     * 基本过滤器 集合
     */
    private final List<BaseFilter> baseFilters = new ArrayList<>();

    /**
     * 做基本过滤
     *
     * @param request  请求
     * @param response 响应
     * @param chain    通道
     */
    public void doBaseHeaders(HttpRequest request, HttpResponse response,
                              BaseFilterChain chain) {
        for (BaseFilter baseFilter : baseFilters) {
            baseFilter.parseHeaders(request, response, chain);
        }
    }

    /**
     * 添加 基本过滤器
     *
     * @param filter 基本过滤器
     */
    public void addBaseFilter(BaseFilter filter) {
        baseFilters.add(filter);
    }
}
